package Help;

import java.util.Scanner;

public class TreeCheck {
	private MyTreeNode root = null;

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		TreeCheck check = new TreeCheck();
		int len = scan.nextInt();
		for (int j = 0; j < len; j++) {
			int i = scan.nextInt();
			MyTreeNode Node = new MyTreeNode();
			Node.setData(i);
			check.SetUpTree(Node, check.getRoot());
		}
		try {
			check.PrintTree(check.getRoot());
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public void SetUpTree(MyTreeNode Node, MyTreeNode Root) {
		if (root == null) {
			root = Node;
		} else {
			if (Node.getData() < Root.getData()) {
				if (Root.getLeChild() == null) {
					Root.setLeChild(Node);
				} else {
					MyTreeNode Node1 = Root.getLeChild();
					SetUpTree(Node, Node1);
				}
			} else {
				if (Root.getRiChild() == null) {
					Root.setRiChild(Node);
				} else {
					MyTreeNode Node1 = Root.getRiChild();
					SetUpTree(Node, Node1);
				}
			}
			System.out.println("Root:" + Root.getData());
		}

	}

	public void PrintTree(MyTreeNode Node) throws Exception {
		if (Node != null) {
			if (Node.getLeChild() != null) {
				MyTreeNode Node1 = Node.getLeChild();
				PrintTree(Node1);
			}
			System.out.println(Node.getData() + " ");
			if (Node.getRiChild() != null) {
				MyTreeNode Node1 = Node.getRiChild();
				PrintTree(Node1);
			}
		}
	}

	public MyTreeNode getRoot() {
		return root;
	}

}
